package com.nidu.demo.file.model;

import com.alibaba.cola.exception.BizException;
import com.nidu.demo.base.BaseDeletableEntity;
import com.nidu.demo.base.BaseTenantEntity;
import com.nidu.demo.common.enums.BooleanEnum;
import com.nidu.demo.common.exception.ErrorCodeConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 文件领域实体
 *
 * @author auto
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class File extends BaseTenantEntity implements BaseDeletableEntity {

    private Long id;

    /**
     * 配置编号
     */
    private Long configId;

    /**
     * 文件名
     */
    private String name;

    /**
     * 文件路径
     */
    private String path;

    /**
     * 文件 URL
     */
    private String url;

    /**
     * 文件类型
     */
    private String type;

    /**
     * 文件大小
     */
    private Long size;

    /**
     * 是否删除
     */
    private Boolean deleted;

    @Override
    public void isDeleted() {
        if (BooleanEnum.TRUE.getValue().equals(this.getDeleted())) {
            throw new BizException(ErrorCodeConstants.FILE_NOT_FOUND.getCode(), ErrorCodeConstants.FILE_NOT_FOUND.getMessage());
        }
    }

    public static File create(Long configId, String name, String path, String url, String type, Long size) {
        File file = new File();
        file.setConfigId(configId)
                .setName(name)
                .setPath(path)
                .setUrl(url)
                .setType(type)
                .setSize(size);
        return file;
    }
}
